/**
 * @param {number[]} prices
 * @return {number}
 */
 var getDescentPeriods = function(prices) {
  const n = prices.length
  const arr = new Array(n).fill(1)
  for(let i = 1; i<n; i++){
    arr[i] = prices[i-1] - prices[i]
  }
  let ans = n
  let l = 0
  for(let r = 0; r<n; r++){
    if(arr[r] == 1){
      let x = r-l+1
      if(r === n-1 || arr[r+1] !== 1) ans += x*(x-1)/2
    }else{
      l = r
    }
  }
  return ans
};